//
// Created by luolijun on 2021/10/31.
//
#include "FacadeItem.h"
#include "utils/asserts.h"

#include <QDebug>

namespace falcon {

FacadeItem::FacadeItem(falcon::Facade* f) {
    ASSERT(f != nullptr);
    setFlag(GraphicsItemFlag::ItemIsMovable);
    setSelected(true);
    facade = f;
}

QRectF FacadeItem::boundingRect() const {
    auto center = facade->place();
    auto size = facade->size();
    auto rect = QRectF { center.x - size.width / 2, center.y - size.height / 2, size.width, size.height };
    qDebug() << QString("FacadeItem: center: %1 %2").arg(center.x).arg(center.y);
    qDebug() << QString("FacadeItem: size:   %1 %2").arg(size.width).arg(size.height);
    qDebug() << QString("FacadeItem: rect:   (%1 %2) - (%3 %4)").arg(rect.left()).arg(rect.top()).arg(rect.right()).arg(rect.bottom());
    return rect;
}

void FacadeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
    this->painter.attach(painter, option, widget);
    facade->draw(this->painter);
}

void FacadeItem::move(const falcon::POINT& pos) {
    facade->place(pos);
    this->update();
}

} // namespace qt
